home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 5
/
Aminet 5 - March 1995.iso
/
Aminet
/
gfx
/
show
/
jpegAGAsrc21.lha
/
jpegAGAsrc
/
jpegAGA
/
scalefit.c
< prev
Wrap
C/C++ Source or Header
|
1995-01-14
|
4KB
|
181 lines
/* Find best scale to fit on the screen */
/* written by Günther Röhrich */
/* for jpegAGA 2.0 */
#ifndef __GNUC__
#include <pragmas/graphics_pragmas.h>
#include <pragmas/exec_pragmas.h>
#include <clib/graphics_protos.h>
#include <clib/exec_protos.h>
#else
#include <inline/graphics.h>
#include <inline/exec.h>
#endif
#include <graphics/modeid.h>
#include <stdio.h>
#include <stdlib.h>
#include "jpeglib.h"
#define HAM8 1
#define TOLERANCE 35
struct WBFlags
{
int scale;
short VGAenable;
short SUPER72enable;
short SMRenable;
short GrayEnable;
short NoSmooth;
short DCTFast;
short ScaleFit;
};
extern struct WBFlags WBFlags;
extern struct GfxBase *GfxBase;
ULONG ScaleFitDisplayID=0;
int FindScaleFit(JDIMENSION width, JDIMENSION height, ULONG Mode)
{
struct DimensionInfo querydims;
ULONG MyDisplayID, NoSUPER72;
JDIMENSION scrwidth, scrheight;
JDIMENSION VGAwidth, VGAheight;
int scale;
ScaleFitDisplayID = 0;
if(!GfxBase)
{
if(!(GfxBase = (struct GfxBase *)OpenLibrary((UBYTE *)"graphics.library",39)))
{
printf("Could not open graphics.library V39 or higher.\n");
return -1;
}
}
/* check if SUPER72 mode is available */
NoSUPER72 = ModeNotAvailable(SUPER72_MONITOR_ID | SUPERHAMLACE_KEY);
MyDisplayID = HIRESLACE_KEY;
if(WBFlags.VGAenable)
{
if(ModeNotAvailable(VGAPRODUCT_KEY))
{
return -1;
}
else
{
if(GetDisplayInfoData(NULL, (UBYTE *)&querydims, sizeof(querydims),DTAG_DIMS,VGAPRODUCT_KEY))
{
/* allow 10 pixels tolerance */
VGAwidth = (JDIMENSION)querydims.StdOScan.MaxX+TOLERANCE;
VGAheight = (JDIMENSION)querydims.StdOScan.MaxY+TOLERANCE;
}
}
MyDisplayID = VGAPRODUCT_KEY;
if(WBFlags.SUPER72enable && !NoSUPER72) MyDisplayID = SUPER72_MONITOR_ID | SUPERLACE_KEY;
}
if(GetDisplayInfoData(NULL, (UBYTE *)&querydims, sizeof(querydims),DTAG_DIMS,MyDisplayID))
{
/* allow 34 pixels tolerance */
scrwidth = (JDIMENSION)querydims.StdOScan.MaxX+TOLERANCE;
scrheight = (JDIMENSION)querydims.StdOScan.MaxY+TOLERANCE;
/* printf("Screen width: %d, height: %d\n", scrwidth-TOLERANCE+1, scrheight-TOLERANCE+1); */
/* printf("Picture width: %d, height: %d\n", width, height); */
/* printf("VGA width: %d, height: %d\n", VGAwidth-TOLERANCE+1, VGAheight-TOLERANCE+1); */
}
else return -1;
for(scale=1; scale<8; scale = scale<<1)
{
if((width / scale <= scrwidth) && (height / scale <= scrheight)) break;
}
/* Find the right screenmode */
/* SUPER72 is the default, when available */
if(WBFlags.SUPER72enable && !NoSUPER72 && WBFlags.VGAenable)
{
if(Mode == HAM8)
{
ScaleFitDisplayID = SUPER72_MONITOR_ID | SUPERHAMLACE_KEY;
}
else
{
ScaleFitDisplayID = SUPER72_MONITOR_ID | SUPERLACE_KEY;
}
}
/* Check for fit on a VGA screen */
if(WBFlags.VGAenable)
{
/* check for fit on a LORES screen */
if((VGAwidth / 2 >= width / scale) && (VGAheight / 2 >= height / scale))
{
if(Mode == HAM8)
{
ScaleFitDisplayID = VGALORESHAMDBL_KEY;
}
else
{
ScaleFitDisplayID = VGALORESDBL_KEY;
}
}
else if((VGAwidth >= width / scale) && (VGAheight >= height / scale) || !WBFlags.SUPER72enable)
{
if(Mode == HAM8)
{
ScaleFitDisplayID = VGAPRODUCTHAM_KEY;
}
else
{
ScaleFitDisplayID = VGAPRODUCT_KEY;
}
}
}
if(ScaleFitDisplayID == 0)
{
/* check for fit on a LORES screen */
if((scrwidth / (scale * 2) >= width) && (scrheight / (scale * 2) >= height))
{
if(Mode == HAM8)
{
ScaleFitDisplayID = HAM_KEY;
}
else
{
ScaleFitDisplayID = LORES_KEY;
}
}
else
{
if(Mode == HAM8)
{
ScaleFitDisplayID = HIRESHAMLACE_KEY;
}
else
{
ScaleFitDisplayID = HIRESLACE_KEY;
}
}
}
return scale;
}